<?php


namespace app\common\caches;

use think\facade\Cache;

/**
 * @todo 用户签到缓存器
 * Class UserSignCache
 * @package app\common\caches
 */
class UserSignCache
{
    public static function getKissStatus(int $user_id)
    {
        return Cache::store('redis')->handler()->hget('user.kiss', $user_id) ?: null;
    }

    public static function setKissStatus(int $user_id, string $date)
    {
        Cache::store('redis')->handler()->hset('user.kiss', $user_id, $date);
    }

    public static function getHugStatus(int $user_id)
    {
        return Cache::store('redis')->handler()->hget('user.hug', $user_id) ?: null;
    }

    public static function setHugStatus(int $user_id, string $date)
    {
        Cache::store('redis')->handler()->hset('user.hug', $user_id, $date);
    }

    public static function getUserSign(int $user_id)
    {
        return Cache::store('redis')->handler()->hget('user.sign', $user_id) ?: null;
    }
    public static function setUserSign(int $user_id, string $date)
    {
        Cache::store('redis')->handler()->hset('user.sign', $user_id, $date);
    }



    /**
     * @todo 缓存用户每日签到情况，用于重复签到判断
     * @param int $uid      用户ID
     * @param string $date  签到日期 Y-m-d
     * @return bool
     */
    public static function setUserDailySignStatus(int $uid, string $date)
    {
        return Cache::tag("user:{$uid}.sign")
            ->set("user:{$uid}.date:{$date}.sign.status", true, 24 * 60 * 60);
    }

    /**
     * @todo 获取用户每日签到情况，用于重复签到判断
     * @param int $uid      用户ID
     * @param string $date  签到日期
     * @return mixed
     */
    public static function getUserDailySignStatus(int $uid, string $date)
    {
        return Cache::get("user:{$uid}.date:{$date}.sign.status") ?? null;
    }

    /**
     * @todo 缓存连续签到天数，24小时失效
     * @param int $uid      用户ID
     * @param string $date  签到日期
     * @param array $data   月签到数据
     * @return bool
     */
    public static function setUserContinueSignDays(int $uid, string $date, array $data)
    {
        return Cache::tag("user:{$uid}.sign")
            ->set("user:{$uid}.date:{$date}.sign.continue.days", $data, 24 * 60 * 60);
    }

    /**
     * @todo 获取连续签到天数
     * @param int $uid      用户ID
     * @param string $date  签到日期
     * @return mixed|null
     */
    public static function getUserContinueSignDays(int $uid, string $date)
    {
        return Cache::get("user:{$uid}.date:{$date}.sign.continue.days") ?? null;
    }

    /**
     * @todo 缓存用户每日签到详情，用于重复签到判断
     * @param int $uid      用户ID
     * @param string $date  签到日期 Y-m-d
     * @param mixed|null $data  签到详情数据
     * @return bool
     */
    public static function setUserDailySignData(int $uid, string $date, $data)
    {
        return Cache::tag("user:{$uid}.sign")
            ->set("user:{$uid}.date:{$date}.sign.data", $data, 24 * 60 * 60);
    }

    /**
     * @todo 获取用户每日签到详情，用于重复签到判断
     * @param int $uid      用户ID
     * @param string $date  签到日期
     * @return mixed
     */
    public static function getUserDailySignData(int $uid, string $date)
    {
        return Cache::get("user:{$uid}.date:{$date}.sign.data") ?? null;
    }

    /**
     * @todo 缓存用户月签到数据
     * @param int $uid      用户ID
     * @param string $month 签到月：Y-M
     * @param array $data  月签到数据
     * @return bool
     */
    public static function setUserMonthSignData(int $uid, string $month, array $data)
    {
        return Cache::tag("user:{$uid}.sign")
            ->set("user:{$uid}.month:{$month}.sign.data", $data, 24 * 60 * 60);
    }

    /**
     * @todo 获取用户月签到数据
     * @param int $uid      用户ID
     * @param string $month 签到月：Y-M
     * @return mixed|null
     */
    public static function getUserMonthSignData(int $uid, string $month)
    {
        return Cache::get("user:{$uid}.month:{$month}.sign.data") ?? null;
    }

    /**
     * @todo 清空用户所有签到相关的缓存数据
     * @param int $uid      用户ID
     * @return bool
     */
    public static function flushUserSignData(int $uid)
    {
        return Cache::tag("user:{$uid}.sign")->clear();
    }
}
